package org.cid54.jshopper.model;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 *
 * @author fgo
 */
@Entity
public class ShoppingList extends SuperEntity {

    @OneToMany(mappedBy = "shoppingList", cascade = CascadeType.REMOVE)
    private Set<ShopItem> shopItems = new HashSet<ShopItem>();
    @Column(nullable = false, length = 50, unique = true)
    private String name;
    @ManyToOne(optional = false)
    private UserGroup userGroup;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Set<ShopItem> getShopItems() {
        return shopItems;
    }

    public void addShopItem(ShopItem shopItem) {
        shopItem.setShoppingList(this);
    }

    public UserGroup getUserGroup() {
        return userGroup;
    }

    public void setUserGroup(UserGroup userGroup) {
        this.userGroup = userGroup;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ShoppingList other = (ShoppingList) obj;
        if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 43 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }
}
